package com.jacobson.huobi.custom.dialogs

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.jacobson.huobi.R
import com.jacobson.huobi.entities.evt.VipRechargeSubmitEvt
import kotlinx.android.synthetic.main.dialog_recharge.*
import kotlinx.android.synthetic.main.fragment_vip.*

@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class RechargeDialog(context: Context, vipRechargeSubmitEvt: VipRechargeSubmitEvt) : Dialog(context) {

    var evt = vipRechargeSubmitEvt

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.dialog_recharge)
        window.setGravity(Gravity.CENTER)
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)

        initBtn()
    }

    public fun setOnclickListener(listener: View.OnClickListener) {
            btnSubMitRecharge.setOnClickListener(listener)
            ivVipRecharge.setOnClickListener(listener)
    }

    /**
     * 是否勾选已充值
     */
    public fun isCharge(): Boolean {
        return cbIsCharge.isChecked
    }

    /**
     * 获取参数
     */
    public fun getDialogSubmitEvt(): VipRechargeSubmitEvt {
        var transactionId = etTransactionId.text.toString()
        var num = etNum.text.toString()
        if (num.isNullOrEmpty()) {
            evt.num = 0.0
        }else {
            evt.num = num.toDouble()
        }
        evt.transaction_id = transactionId
        return evt
    }

    /**
     * 图片回显
     */
    public fun setIvRecharge(url: String) {
        Glide.with(this.context).load(url).into(ivVipRecharge)
    }

    private fun initBtn() {
        btnBack.setOnClickListener{
            this.dismiss()
        }
    }
}